package com.zju.cst.spider.utils;

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class StreamUtils {

	public static void close(Closeable close){
		if(close != null){
			try{
				close.close();
			}
			catch(Exception e){
				throw new RuntimeException("流未能正确关闭!");
			}
		}
	}
	
	public static List<String> getStopWord(String path){
		List<String> list = new ArrayList<String>();
		try {
			InputStream in = StreamUtils.class.getClassLoader().getResourceAsStream(path);
			BufferedReader buf = new BufferedReader(new InputStreamReader(in));
			String str = null;
			while((str = buf.readLine()) != null){
				list.add(str);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return list;
	}
}
